package com.ds.robot.assistant.controller;

import com.ds.robot.assistant.entity.TargetAchievementEntity;
import com.ds.robot.assistant.vo.req.TargetAchievementRequest;
import com.ds.robot.assistant.service.TargetAchievementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 作用：
 *
 * @author WeiShaoying
 * 
 */
@RestController
@RequestMapping("/target")
@Slf4j
public class TargetController {

    private final TargetAchievementService targetAchievementService;

    @Autowired
    public TargetController(TargetAchievementService targetAchievementService) {
        this.targetAchievementService = targetAchievementService;
    }


    @PostMapping(value = "/create")
    public ResponseEntity<Boolean> create(@RequestBody TargetAchievementRequest request) {
        TargetAchievementEntity entity = new TargetAchievementEntity();
        BeanUtils.copyProperties(request, entity);
        entity.setTargetTypeId(909);
        return ResponseEntity.ok(targetAchievementService.save(entity));
    }

    // @GetMapping("/{id}")
    // public ResponseEntity<TargetAchievementEntity> read(@PathVariable Long id) {
    //     TargetAchievementEntity TargetAchievementEntity = TargetAchievementEntityService.read(id);
    //     if (TargetAchievementEntity != null) {
    //         return ResponseEntity.ok(TargetAchievementEntity);
    //     } else {
    //         return ResponseEntity.notFound().build();
    //     }
    // }
    //
    // @PutMapping("/{id}")
    // public ResponseEntity<TargetAchievementEntity> update(@PathVariable Long id, @RequestBody TargetAchievementEntityRequest request) {
    //     TargetAchievementEntity updated = TargetAchievementEntityService.update(id, request);
    //     if (updated != null) {
    //         return ResponseEntity.ok(updated);
    //     } else {
    //         return ResponseEntity.notFound().build();
    //     }
    // }
    //
    // @DeleteMapping("/{id}")
    // public ResponseEntity<Void> delete(@PathVariable Long id) {
    //     boolean deleted = TargetAchievementEntityService.delete(id);
    //     if (deleted) {
    //         return ResponseEntity.noContent().build();
    //     } else {
    //         return ResponseEntity.notFound().build();
    //     }
    // }
    //
    @GetMapping(value = "/list")
    public ResponseEntity<List<TargetAchievementEntity>> list() {
        List<TargetAchievementEntity> list = this.targetAchievementService.list();
        return ResponseEntity.ok(list);
    }


}
